package com.asm.blog.controller;


import com.asm.blog.common.lang.Result;
import com.asm.blog.entity.User;
import com.asm.blog.service.UserService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author asm付
 * @since 2021-06-01
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 保存用户
     *
     * @Validated 注解用来 校验前端参数 与 实体类的  @NotBlank(message = "昵称不能空") 校验
     */
    @PostMapping("/save")
    public Result save(@Validated @RequestBody User user)
    {

        return Result.succ("成功");
    }


    /**
     * 获取用户
     */
    @RequiresAuthentication
    @GetMapping("/detail/{id}")
    public Object detail(@PathVariable("id") Long id)
    {
        User detail = userService.getById(id);


        return Result.succ(detail);
    }


}
